﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Wys.DataForm.CSharp
{
    public partial class BackUpTime : Wys.Control.Vb.AutoAdjustFrom
    {
        public BackUpTime()
        {
            InitializeComponent();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.Close();
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            if (radAll.Checked)
            {
                if (ShowMessageResult("是否全部备份，此备份比较花费时间，备份吗？") != DialogResult.Yes)
                {
                    return;
                }
            }
            this.DialogResult = System.Windows.Forms.DialogResult.Yes;
            this.Close();
        }

        private void ChangeState(Object ob, EventArgs e)
        {
            System.Windows.Forms.RadioButton mrb = ob as System.Windows.Forms.RadioButton;
            if (mrb != null)
            {
                if (mrb.Name == "radAll"&&mrb.Checked)
                {
                    this.groupBox9.Enabled = false;
                    groupBox8.Enabled = false;
                    chkSoftWare.Visible = false;
                }
                else if (mrb.Name == "radSingle" && mrb.Checked)
                {
                    this.groupBox9.Enabled = true;
                    groupBox8.Enabled = true;
                    chkSoftWare.Visible = true;
                }
            }
        }

        private void BackUpTime_Load(object sender, EventArgs e)
        {
            this.radAll.CheckedChanged += new EventHandler(ChangeState);
            this.radSingle.CheckedChanged += new EventHandler(ChangeState);     
            groupBox8.Enabled = false;
            this.groupBox9.Enabled = false;

            //A-2010-02-23 修正开始时间为数据库的版本时间
            ADODB.Recordset rs = ct.GetTable("select * from XSCVersion");
            if (!rs.EOF)
            {
                this.dtGroup2Start.Text = DateTime.Parse(rs.Fields["DateTime"].Value.ToString()).ToString("yyyy-MM-dd HH:mm:ss");
                rs.Close();
            }
            //A-2010-02-23 修正开始时间为数据库的版本时间
        }

        //类型
        public int Type1
        {
            get
            {
                if (radAll.Checked)
                {
                    return 0;
                }
                else
                {
                    return 1;
                }
            }
        }
        //备份开始时间
        public DateTime DataStartTime
        {
            get
            {
                return dtGroup2Start.Value;
            }
        }
        //结束时间
        public DateTime DataEndTime
        {
            get
            {
                return dtGroup2End.Value;
            }
        }

        /// <summary>
        /// 1 为所有 0 为时间备份
        /// </summary>
        public String 数据库备份类型
        {
            get
            {
                if (myRadioButton1.Checked)
                {
                    return "1";
                }
                else
                {
                    return "0";
                }
            }            
        }

        /// <summary>
        /// 1 为所有 0 为时间备份
        /// </summary>
        public String 附件备份类型
        {
            get
            {
                if (myRadioButton6.Checked)
                {
                    return "1";
                }
                else
                {
                    return "0";
                }
            }
        }

        /// <summary>
        /// 1 为所有 0 为时间备份
        /// </summary>
        public String 图片备份类型
        {
            get
            {
                if (myRadioButton4.Checked)
                {
                    return "1";
                }
                else
                {
                    return "0";
                }
            }
        }

        /// <summary>
        /// 1 为所有 0 为时间备份
        /// </summary>
        public String 小软件备份类型
        {
            get
            {
                if (myRadioButton7.Checked)
                {
                    return "1";
                }
                else
                {
                    return "0";
                }
            }
        }

        private void StateChange(object sender, EventArgs e)
        {
            if ((!this.chkGroup3Att.Checked) && (!this.chkGroup3Database.Checked) && (!this.chkGroup3Image.Checked) && (!chkSoftWare.Checked))
            {
                this.btnOk.Enabled = false;               
            }
            else
            {
                this.btnOk.Enabled = true;               
            }

            if (chkGroup3Database.Checked)
            {
                groupBox4.Enabled = true;
            }
            else
            {
                groupBox4.Enabled = false;
            }

            if (chkGroup3Att.Checked)
            {
                groupBox6.Enabled = true;
            }
            else
            {
                groupBox6.Enabled = false;
            }

            if (chkGroup3Image.Checked)
            {
                groupBox5.Enabled = true;
            }
            else
            {
                groupBox5.Enabled = false;
            }

            if (chkSoftWare.Checked)
            {
                groupBox7.Enabled = true;
            }
            else
            {
                groupBox7.Enabled = false;
            }
        }

        public String BackLocation
        {           
            get
            {
                String strTemp="";
                if (radEmail.Checked)
                {
                    strTemp += "1";
                }
                else
                {
                    strTemp += "0";
                }

                if (radLocal.Checked)
                {
                    strTemp += "1";
                }
                else
                {
                    strTemp += "0";
                }
               return strTemp;
            }
           
        }
        //备份数据库 文件 图片 三位字符串
        public String BackType
        {
            get
            {
                String strTemp = "";
                if (chkGroup3Database.Checked)
                {
                    strTemp += "1";
                }
                else
                {
                    strTemp += "0";
                }
                if (chkGroup3Att.Checked)
                {
                    strTemp += "1";
                }
                else
                {
                    strTemp += "0";
                }
                if (chkGroup3Image.Checked)
                {
                    strTemp += "1";
                }
                else
                {
                    strTemp += "0";
                }

                if (chkSoftWare.Checked)
                {
                   strTemp += "1";
                }
                else
                {
                    strTemp += "0";
                }
                return strTemp;
            }
        }

        
    }
}
